home *** CD-ROM | disk | FTP | other *** search
- Path: news.chattanooga.net!usenet
- From: "Eric W. Bradway" <ebradway@microsports.com>
- Newsgroups: comp.lang.c
- Subject: Re: Problem...Problem!
- Date: Wed, 31 Jan 1996 13:16:55 -0500
- Organization: Micro Sports, Inc.
- Message-ID: <310FB217.280C@microsports.com>
- References: <4el09q$6im@ratree.psu.ac.th>
- NNTP-Posting-Host: 205.244.28.38
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b5 (Win95; I)
-
- Sanon CHAOCHAIYAPORN wrote:
- > #define NUM 8
- > #define ERR 1e-4
-
- Try avoiding the scientific notation by doing a divide by 10000 and
- comparing to 1. I assume this isn't a time-critical routine so the extra
- divide won't hurt. If it is time-critical, rewrite the program using
- long ints.
-
- > v[i] = (v[i+1] + v[i+2]) / 8;
- > v[i+1] = (v[i] + v[i+3] + 40) / 8;
- > v[i+2] = (v[i] + v[i+3] + v[i+5] + 50) / 8;
- > v[i+3] = (v[i+1] + v[i+2] + 110) / 8;
- > v[i+4] = (v[i+5] + v[i+6] + 150) / 8;
- > v[i+5] = (v[i+2] + v[i+4] + v[i+7] + 70) / 8;
- > v[i+6] = (v[i+4] + v[i+7] + 200) / 8;
- > v[i+7] = (v[i+5] + v[i+6] + 200) / 8;
-
- Your problem may lie here - add a .0 to each numeric constant (e.g.,
- 8.0, 40.0, 110.0) to get the compiler to treat them as floats. Many
- compilers automatically convert everything to ints if you don't
- specifically show that the values/variables are floats.
-
- And of course, on closer inspection, when do you assign meaningful
- values to v[]? Do you mean to initialize to zero and get the following
- results on the first pass:
- v[0] = 0
- v[1] = 5
- v[2] = 6.25
- v[3] = 14.53125
- v[4] = 18.75
- v[5] = 11.875
- v[6] = 27.34375
- v[7] = 29.90234
-
- You seem to be making your program much more complex than necessary!
-
- -Eric
-